
import React from "react"
import Appcss1 from "./css/Reg.module.css"
import fanh from '../../assets/icons/返回箭头.png'
import { List,  InputItem} from 'antd-mobile';
import { Toast, WhiteSpace, WingBlank, Button } from 'antd-mobile';
// import { createForm } from 'rc-form';
// import Logo from '../assets/icons/logo.png'
class Regyzm extends React.Component {
    constructor(){
        super()
        this.state={
            phone:"",
            mima:"",
            check:""
        }
    }
    ipt1(e){
       
        var uPattern = /^1\d{10}$/;
        if(!uPattern.test(e.target.value)){
            Toast.offline('手机号必须是11位!', 1);
        }
        else{
            
            this.setState({
                    phone:e.target.value,
                })
            // fetch(`http://106.12.10.151:3000/cellphone/existence/check?phone=${e.target.value}`)
            // .then(body=>body.json())
            // .then(res=>{
            //     console.log(res)
            //     if(res.exist==1){
            //         Toast.fail('账号已注册', 1);  
            //     }
            // })
           
        }

    }
    send(){
         fetch(`http://106.12.10.151:3000/cellphone/existence/check?phone=${this.state.phone}`,{  credentials:'include'})
            .then(body=>body.json())
            .then(res=>{
                console.log(res)
                if(res.exist==1){
                    Toast.fail('账号已注册', 1);  
                }
                else{
                    fetch(`http://106.12.10.151:3000/captcha/sent?phone=${this.state.phone}`,{  credentials:'include'})
        .then(body=>body.json())
        .then(res=>{
            if(res.code==200){
                Toast.loading('success...', 1, () => {
                    this.props.history.push({pathname:"/shouyzm",phone:this.state.phone})
                  });
               
            }
            else{
                Toast.fail('输入错误', 1); 
            }
        })
                }
            })
        
        // .catch(
        //     Toast.fail('账号或密码错误', 1);
        // )
    }
    fanh(){
        this.props.history.push({pathname:"/login"})
    }
    render(){
        return(
           
        <div className={Appcss1.cel_log}>
             <div className={Appcss1.cel_zc}>
                <span id={Appcss1.cel_fh} onClick={this.fanh.bind(this)}><img src={fanh} width='100%' height='100%' alt=''/></span>
                <span id={Appcss1.cel_reg}>手机号注册</span>
                
            </div>
            <div >
            <h5>输入手机号发送验证码</h5>
             </div>
             <div >
               <input type="text" className={Appcss1.cel_pa} placeholder="请输入手机号"  onBlur={this.ipt1.bind(this)}></input>
             </div>
             
            
			<button className={Appcss1.cel_re} onClick={this.send.bind(this)}>下一步</button><br/>
            {/* <span className={Appcss.cel_qtdl}>&lt;其他登录方式</span> */}
		</div>
    
        )
    }



}
// const Cell_login1 = createForm()(Cell_login);
export default Regyzm